class BubbleManager {
    constructor(map) {
        this._map = map;
        this.custom = new GeoGlobe.Visuals.Custom();
        this.custom.addTo(map);
        this.bubble = null;

    }

    //添加一个makrer
    addBubble(coordinates) {

        return new Promise((resolve, reject) => {

            if (this.bubble === null) {
                let custom = this.custom;
                let features_data = [];
                features_data.push({
                    "type": "Feature",
                    "properties": {},
                    geometry: {
                        type: 'Point',
                        coordinates: coordinates
                    },
                    "itemStyle": null,
                    "label": null,
                    "emphasis": null
                });
                // 构造气泡图层
                this.bubble = new GeoGlobe.Visuals.Custom.Bubble({
                    id: "bubble_3",
                    visibility: true,
                    dragdrawing: false,
                    data: features_data,
                    rendererOptions: {
                        markPoint: {
                            hoverable: false,
                            clickable: false,
                            symbol: "bubble",
                            symbolMinSize: 20,
                            symbolMaxSize: 100,
                            effect: {
                                show: true,
                                scaleSize: 1,
                                period: 10
                            },
                            itemStyle: {
                                "color": {
                                    "0": "rgba(135,196,240,0.7)",
                                    "0.5": "rgba(255,255,0,0.7)",
                                    "1": "rgba(35,168,242,0.6)"
                                },
                                shadowColor: '#000',
                                shadowBlur: 0,
                                shadowOffsetX: 0,
                                shadowOffsetY: 0
                            },
                            label: {
                                show: false,
                                color: "#fff",
                                align: "center",
                                baseline: "middle",
                                fontFamily: "serif",
                                fontSize: 12,
                                fontStyle: "normal",
                                fontWeight: "normal"
                            }
                        },
                        tooltip: {
                            show: true,
                            backgroundColor: "rgba(0,0,0,0.7)",
                            borderColor: "#333",
                            borderRadius: 0,
                            borderWidth: 0,
                            padding: 5,
                            textStyle: {
                                color: "#fff",
                                fontFamily: "Microsoft YaHei",
                                fontSize: 12,
                                fontStyle: "normal",
                                fontWeight: "normal"
                            }
                        }
                    }
                });

                // 添加到可视化定制图层
                this.bubble.addTo(custom);
                // TODO 暂时屏蔽水纹波
                // bubble3.setVisible(true);
                this.bubble.setVisible(true)
                // 绘制
                custom.render();
                resolve(true);
            } else {
                resolve(true);
            }


        });

        // return this.bubble;
    }

    getBubble() {
        return this.bubble;
    }

    setBubble(coordinates) {
        if (this.bubble !== null) {
            let features_data = [];
            features_data.push({
                "type": "Feature",
                "properties": {},
                geometry: {
                    type: 'Point',
                    coordinates: coordinates
                },
                "itemStyle": null,
                "label": null,
                "emphasis": null
            });
            this.bubble.setData(features_data);
        }


    }


    hide() {
        if (this.bubble !== null) {
            this.bubble.setVisible(false);
        }

    }

    show() {
        if (this.bubble !== null) {
            this.bubble.setVisible(true);
        }


    }

}

export {BubbleManager}

export default BubbleManager